/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package com.feiyue.basic.server.parser;

import java.io.PrintStream;
import java.io.UnsupportedEncodingException;

public class Base64
{

	private static final byte decodingTable[];
	private static final byte encodingTable[];


	public static String decode(String s, String s1)
	{
	    String s2 = s;
		if (s != null && s.length() != 0) {
		    s2 = "so sad";
	        String s3;
            try {
                s3 = new String(decode(s), s1);
                s2 = s3;
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
		}
		
		return s2;
	}

	public static byte[] decode(String s)
	{
		String s1 = discardNonBase64Chars(s);
		byte abyte0[];
		int i;
		int j;
		if (s1.charAt(-2 + s1.length()) == '=')
			abyte0 = new byte[1 + 3 * (-1 + s1.length() / 4)];
		else
		if (s1.charAt(-1 + s1.length()) == '=')
			abyte0 = new byte[2 + 3 * (-1 + s1.length() / 4)];
		else
			abyte0 = new byte[3 * (s1.length() / 4)];
		i = 0;
		j = 0;
		
		byte byte0;
        byte byte1;
        byte byte2;
        byte byte3;
		do
		{
			if (i >= -4 + s1.length())
			{
				
				if (s1.charAt(-2 + s1.length()) == '=')
				{
					byte byte11 = decodingTable[s1.charAt(-4 + s1.length())];
					byte byte12 = decodingTable[s1.charAt(-3 + s1.length())];
					abyte0[-1 + abyte0.length] = (byte)(byte11 << 2 | byte12 >> 4);
				} else
				if (s1.charAt(-1 + s1.length()) == '=')
				{
					byte byte8 = decodingTable[s1.charAt(-4 + s1.length())];
					byte byte9 = decodingTable[s1.charAt(-3 + s1.length())];
					byte byte10 = decodingTable[s1.charAt(-2 + s1.length())];
					abyte0[-2 + abyte0.length] = (byte)(byte8 << 2 | byte9 >> 4);
					abyte0[-1 + abyte0.length] = (byte)(byte9 << 4 | byte10 >> 2);
				} else
				{
					byte byte4 = decodingTable[s1.charAt(-4 + s1.length())];
					byte byte5 = decodingTable[s1.charAt(-3 + s1.length())];
					byte byte6 = decodingTable[s1.charAt(-2 + s1.length())];
					byte byte7 = decodingTable[s1.charAt(-1 + s1.length())];
					abyte0[-3 + abyte0.length] = (byte)(byte4 << 2 | byte5 >> 4);
					abyte0[-2 + abyte0.length] = (byte)(byte5 << 4 | byte6 >> 2);
					abyte0[-1 + abyte0.length] = (byte)(byte7 | byte6 << 6);
				}
				return abyte0;
			}
			byte0 = decodingTable[s1.charAt(i)];
			byte1 = decodingTable[s1.charAt(i + 1)];
			byte2 = decodingTable[s1.charAt(i + 2)];
			byte3 = decodingTable[s1.charAt(i + 3)];
			abyte0[j] = (byte)(byte0 << 2 | byte1 >> 4);
			abyte0[j + 1] = (byte)(byte1 << 4 | byte2 >> 2);
			abyte0[j + 2] = (byte)(byte3 | byte2 << 6);
			i += 4;
			j += 3;
		} while (true);
	}

	public static byte[] decode(byte abyte0[])
	{
		byte abyte1[] = discardNonBase64Bytes(abyte0);
		byte abyte2[];
		int i;
		int j;
		if (abyte1[-2 + abyte1.length] == 61)
			abyte2 = new byte[1 + 3 * (-1 + abyte1.length / 4)];
		else
		if (abyte1[-1 + abyte1.length] == 61)
			abyte2 = new byte[2 + 3 * (-1 + abyte1.length / 4)];
		else
			abyte2 = new byte[3 * (abyte1.length / 4)];
		i = 0;
		j = 0;
		
		byte byte0;
        byte byte1;
        byte byte2;
        byte byte3;
		do
		{
			if (i >= -4 + abyte1.length)
			{
				
				if (abyte1[-2 + abyte1.length] == 61)
				{
					byte byte11 = decodingTable[abyte1[-4 + abyte1.length]];
					byte byte12 = decodingTable[abyte1[-3 + abyte1.length]];
					abyte2[-1 + abyte2.length] = (byte)(byte11 << 2 | byte12 >> 4);
				} else
				if (abyte1[-1 + abyte1.length] == 61)
				{
					byte byte8 = decodingTable[abyte1[-4 + abyte1.length]];
					byte byte9 = decodingTable[abyte1[-3 + abyte1.length]];
					byte byte10 = decodingTable[abyte1[-2 + abyte1.length]];
					abyte2[-2 + abyte2.length] = (byte)(byte8 << 2 | byte9 >> 4);
					abyte2[-1 + abyte2.length] = (byte)(byte9 << 4 | byte10 >> 2);
				} else
				{
					byte byte4 = decodingTable[abyte1[-4 + abyte1.length]];
					byte byte5 = decodingTable[abyte1[-3 + abyte1.length]];
					byte byte6 = decodingTable[abyte1[-2 + abyte1.length]];
					byte byte7 = decodingTable[abyte1[-1 + abyte1.length]];
					abyte2[-3 + abyte2.length] = (byte)(byte4 << 2 | byte5 >> 4);
					abyte2[-2 + abyte2.length] = (byte)(byte5 << 4 | byte6 >> 2);
					abyte2[-1 + abyte2.length] = (byte)(byte7 | byte6 << 6);
				}
				return abyte2;
			}
			byte0 = decodingTable[abyte1[i]];
			byte1 = decodingTable[abyte1[i + 1]];
			byte2 = decodingTable[abyte1[i + 2]];
			byte3 = decodingTable[abyte1[i + 3]];
			abyte2[j] = (byte)(byte0 << 2 | byte1 >> 4);
			abyte2[j + 1] = (byte)(byte1 << 4 | byte2 >> 2);
			abyte2[j + 2] = (byte)(byte3 | byte2 << 6);
			i += 4;
			j += 3;
		} while (true);
	}

	private static byte[] discardNonBase64Bytes(byte abyte0[])
	{
		byte abyte1[] = new byte[abyte0.length];
		int i = 0;
		int j = 0;
		do
		{
			if (j >= abyte0.length)
			{
				byte abyte2[] = new byte[i];
				System.arraycopy(abyte1, 0, abyte2, 0, i);
				return abyte2;
			}
			if (isValidBase64Byte(abyte0[j]))
			{
				int k = i + 1;
				abyte1[i] = abyte0[j];
				i = k;
			}
			j++;
		} while (true);
	}

	private static String discardNonBase64Chars(String s)
	{
		StringBuffer stringbuffer = new StringBuffer();
		int i = s.length();
		int j = 0;
		do
		{
			if (j >= i)
				return stringbuffer.toString();
			if (isValidBase64Byte((byte)s.charAt(j)))
				stringbuffer.append(s.charAt(j));
			j++;
		} while (true);
	}

	public static String encode(String s, String s1)
		throws Exception
	{
		if (s != null && s.length() != 0) {
		    byte abyte0[] = encode(s.getBytes(s1), 0);
	        StringBuffer stringbuffer = new StringBuffer(abyte0.length);
	        int i = 0;
	        
	        while (i < abyte0.length) {
	            stringbuffer.append((char)abyte0[i]);
	            i++;
	        }
	        
	        s = stringbuffer.toString();
		}
		
		return s;
	}

	public static byte[] encode(byte abyte0[], int i)
	{
		byte abyte1[];
		int i1;
		int j1;
		int j = abyte0.length - i;
		int k = j % 3;
		int l;
		if (k == 0)
			abyte1 = new byte[(j * 4) / 3];
		else
			abyte1 = new byte[4 * (1 + j / 3)];
		l = abyte0.length - k;
		i1 = i;
		j1 = 0;
		
		while (i1 < l) {
		    int k1 = 0xff & abyte0[i1];
	        int l1 = 0xff & abyte0[i1 + 1];
	        int i2 = 0xff & abyte0[i1 + 2];
	        abyte1[j1] = encodingTable[0x3f & k1 >>> 2];
	        abyte1[j1 + 1] = encodingTable[0x3f & (k1 << 4 | l1 >>> 4)];
	        abyte1[j1 + 2] = encodingTable[0x3f & (l1 << 2 | i2 >>> 6)];
	        abyte1[j1 + 3] = encodingTable[i2 & 0x3f];
	        i1 += 3;
	        j1 += 4;
		}
		
		switch (k) {
        case 0:
            
            break;
        case 1:
            int k3 = 0xff & abyte0[-1 + abyte0.length];
            int l3 = 0x3f & k3 >>> 2;
            int i4 = 0x3f & k3 << 4;
            abyte1[-4 + abyte1.length] = encodingTable[l3];
            abyte1[-3 + abyte1.length] = encodingTable[i4];
            abyte1[-2 + abyte1.length] = 61;
            abyte1[-1 + abyte1.length] = 61;
            break;
        case 2:
            int j2 = 0xff & abyte0[-2 + abyte0.length];
            int k2 = 0xff & abyte0[-1 + abyte0.length];
            int l2 = 0x3f & j2 >>> 2;
            int i3 = 0x3f & (j2 << 4 | k2 >>> 4);
            int j3 = 0x3f & k2 << 2;
            abyte1[-4 + abyte1.length] = encodingTable[l2];
            abyte1[-3 + abyte1.length] = encodingTable[i3];
            abyte1[-2 + abyte1.length] = encodingTable[j3];
            abyte1[-1 + abyte1.length] = 61;
            break;

        default:
            break;
        }
		
		return abyte1;
	}

	private static boolean isValidBase64Byte(byte byte0)
	{
		boolean flag = true;
		if (byte0 != 61) {
		    if (byte0 < 0 || byte0 >= 128)
	            flag = false;
	        else
	        if (decodingTable[byte0] == -1)
	            flag = false;
		}
		return flag;
	}

	public static void main(String args[])
		throws Exception
	{
		String s = decode(encode("我<>们AGDSAG34W123VBGsdgargregre", "UTF-8"), "UTF-8");
		System.out.println(s);
	}

	static 
	{
		int i;
		byte abyte0[] = new byte[64];
		abyte0[0] = 65;
		abyte0[1] = 66;
		abyte0[2] = 67;
		abyte0[3] = 68;
		abyte0[4] = 69;
		abyte0[5] = 70;
		abyte0[6] = 71;
		abyte0[7] = 72;
		abyte0[8] = 73;
		abyte0[9] = 74;
		abyte0[10] = 75;
		abyte0[11] = 76;
		abyte0[12] = 77;
		abyte0[13] = 78;
		abyte0[14] = 79;
		abyte0[15] = 80;
		abyte0[16] = 81;
		abyte0[17] = 82;
		abyte0[18] = 83;
		abyte0[19] = 84;
		abyte0[20] = 85;
		abyte0[21] = 86;
		abyte0[22] = 87;
		abyte0[23] = 88;
		abyte0[24] = 89;
		abyte0[25] = 90;
		abyte0[26] = 97;
		abyte0[27] = 98;
		abyte0[28] = 99;
		abyte0[29] = 100;
		abyte0[30] = 101;
		abyte0[31] = 102;
		abyte0[32] = 103;
		abyte0[33] = 104;
		abyte0[34] = 105;
		abyte0[35] = 106;
		abyte0[36] = 107;
		abyte0[37] = 108;
		abyte0[38] = 109;
		abyte0[39] = 110;
		abyte0[40] = 111;
		abyte0[41] = 112;
		abyte0[42] = 113;
		abyte0[43] = 114;
		abyte0[44] = 115;
		abyte0[45] = 116;
		abyte0[46] = 117;
		abyte0[47] = 118;
		abyte0[48] = 119;
		abyte0[49] = 120;
		abyte0[50] = 121;
		abyte0[51] = 122;
		abyte0[52] = 48;
		abyte0[53] = 49;
		abyte0[54] = 50;
		abyte0[55] = 51;
		abyte0[56] = 52;
		abyte0[57] = 53;
		abyte0[58] = 54;
		abyte0[59] = 55;
		abyte0[60] = 56;
		abyte0[61] = 57;
		abyte0[62] = 43;
		abyte0[63] = 47;
		encodingTable = abyte0;
		decodingTable = new byte[128];
		i = 0;
		
		while (i < 128) {
		    decodingTable[i] = -1;
	        i++;
		}
		
		int j = 65;
		
		while (j <= 90) {
		    decodingTable[j] = (byte)(j - 65);
	        j++;
		}
		
		int k = 97;
		
		while (k <= 122) {
		    decodingTable[k] = (byte)(26 + (k - 97));
	        k++;
		}
		
		int l = 48;
		
		while (l <= 57) {
		    decodingTable[l] = (byte)(52 + (l - 48));
	        l++;
		}
		
		decodingTable[43] = 62;
        decodingTable[47] = 63;
	}
}